package ifosup.matthias.swing;

import java.awt.BorderLayout;
import java.awt.Component;
//import java.awt.Desktop;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//import java.awt.event.ComponentEvent;
//import java.awt.event.ComponentListener;
//import java.awt.event.ContainerEvent;
//import java.awt.event.ContainerListener;
//import java.net.URI;
//import java.rmi.server.UID;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Main
{
	private JFrame frame = new JFrame();
	private JTextField textField_1 = new JTextField("0",20);
	private int i =9;
	
	public Main()
	{
		super();
		BorderLayout calculatrice = new BorderLayout();
		JPanel calc = new JPanel(calculatrice);		
		calc.add(this.textField_1, BorderLayout.NORTH);
		calc.add(this.panelCenter(), BorderLayout.CENTER);
		calc.add(this.panelRight(), BorderLayout.EAST);
		frame.add(calc);
		frame.pack();
		this.frame.setVisible(true);
	}	
	
	
	private Component panelCenter()
	{
		GridLayout button = new GridLayout(0,3);
		JPanel panel = new JPanel(button);

		for (i=9;i>=0;i--)
		{
			JButton but = new JButton(""+i);
			panel.add(but);
			but.addActionListener(new ActionListener()
			{
				@Override
				public void actionPerformed(ActionEvent e) {
					textField_1.setText(""+i);	
				}
		
			});
			
		}
		panel.add(new JButton("="));

		return panel;
		
	}
	
	private Component panelRight()
	{
		GridLayout button = new GridLayout(0,1);
		JPanel panel = new JPanel(button);

		panel.add(new JButton("+"));
		panel.add(new JButton("-"));
		panel.add(new JButton("*"));
		panel.add(new JButton("/"));

		
		return panel;
	}




	public static void main(String[] args)
	{
		new Main();
	}


}
